﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Teigha.Core
{
	public class OdRxDynamicLinker : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdRxDynamicLinker(IntPtr cPtr, bool cMemoryOwn) : base(GlobalsPINVOKE.OdRxDynamicLinker_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdRxDynamicLinker obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdRxDynamicLinker()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							GlobalsPINVOKE.delete_OdRxDynamicLinker(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdRxDynamicLinker cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdRxDynamicLinker_cast(OdRxObject.getCPtr(pObj));
			OdRxDynamicLinker result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxDynamicLinker)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxDynamicLinker)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxDynamicLinker)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdRxDynamicLinker_desc(), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdRxDynamicLinker_isA(this.swigCPtr), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdRxDynamicLinker_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdRxDynamicLinker createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdRxDynamicLinker_createObject();
			OdRxDynamicLinker result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxDynamicLinker)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxDynamicLinker)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxDynamicLinker)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void addReactor(OdRxDLinkerReactor pReactor)
		{
			GlobalsPINVOKE.OdRxDynamicLinker_addReactor(this.swigCPtr, OdRxDLinkerReactor.getCPtr(pReactor));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void removeReactor(OdRxDLinkerReactor pReactor)
		{
			GlobalsPINVOKE.OdRxDynamicLinker_removeReactor(this.swigCPtr, OdRxDLinkerReactor.getCPtr(pReactor));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual OdRxModule loadModule(string moduleFileName, bool silent)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdRxDynamicLinker_loadModule__SWIG_0(this.swigCPtr, moduleFileName, silent);
			OdRxModule result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdRxModule loadModule(string moduleFileName)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdRxDynamicLinker_loadModule__SWIG_1(this.swigCPtr, moduleFileName);
			OdRxModule result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool unloadModule(string moduleFileName)
		{
			bool result = GlobalsPINVOKE.OdRxDynamicLinker_unloadModule(this.swigCPtr, moduleFileName);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool unloadUnreferenced()
		{
			bool result = GlobalsPINVOKE.OdRxDynamicLinker_unloadUnreferenced(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdRxModule loadApp(string applicationName, bool silent)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdRxDynamicLinker_loadApp__SWIG_0(this.swigCPtr, applicationName, silent);
			OdRxModule result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdRxModule loadApp(string applicationName)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdRxDynamicLinker_loadApp__SWIG_1(this.swigCPtr, applicationName);
			OdRxModule result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdRxSystemServices sysServices()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdRxDynamicLinker_sysServices(this.swigCPtr);
			OdRxSystemServices result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxSystemServices)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxSystemServices)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxSystemServices)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdRxDictionary sysRegistry()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdRxDynamicLinker_sysRegistry(this.swigCPtr);
			OdRxDictionary result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxDictionary)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxDictionary)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxDictionary)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdRxModule loadModuleObj(OdRxModule pModuleObj, bool bSilent)
		{
			OdRxModule result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdRxDynamicLinker_loadModuleObj__SWIG_0(this.swigCPtr, OdRxModule.getCPtr(pModuleObj), bSilent), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdRxModule loadModuleObj(OdRxModule pModuleObj)
		{
			OdRxModule result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(GlobalsPINVOKE.OdRxDynamicLinker_loadModuleObj__SWIG_1(this.swigCPtr, OdRxModule.getCPtr(pModuleObj)), false);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual int getModuleCount()
		{
			int result = GlobalsPINVOKE.OdRxDynamicLinker_getModuleCount(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdRxModule getModule(int index, ref string key)
		{
			IntPtr intPtr = Marshal.StringToCoTaskMemUni(key);
			IntPtr value = intPtr;
			OdRxModule result;
			try
			{
				MemoryManager memoryManager = MemoryManager.GetMemoryManager();
				MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
				IntPtr p = GlobalsPINVOKE.OdRxDynamicLinker_getModule__SWIG_0(this.swigCPtr, index, ref intPtr);
				OdRxModule odRxModule;
				if (currentTransaction != null)
				{
					currentTransaction.AddObject((OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
					odRxModule = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
				}
				else
				{
					odRxModule = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
				}
				if (GlobalsPINVOKE.SWIGPendingException.Pending)
				{
					throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
				}
				result = odRxModule;
			}
			finally
			{
				if (intPtr != value)
				{
					key = Marshal.PtrToStringUni(intPtr);
				}
			}
			return result;
		}

		public virtual OdRxModule getModule(string key)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdRxDynamicLinker_getModule__SWIG_1(this.swigCPtr, key);
			OdRxModule result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxModule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;
	}
}
